colors = Array('#aaaaaa','#aa0000','#008800','#0000aa','#888800','#008888','#880088','#000000');
colorshi = Array('#eeeeee','#aa5555','#558855','#5555aa','#888855','#558888','#885588','#000000');

chatlog = new Array('Welcome to c0nflict.','<br>');
statuslog = new Array('','');
    var cell_width=0;
    var cell_height=0;
    var whoami=0;
    var total_dice = 50;
    player_tot = [0,0,0,0,0,0,0];
    player_lan = [0,0,0,0,0,0,0];
    player_plu = [0,0,0,0,0,0,0];
    rainbowG = [0,0];
    diceG = [0,0];

IE6=0;
UA=1;
if (navigator.appVersion.indexOf("MSIE")!=-1) { 
UA = 0;

temp=navigator.appVersion.split("MSIE");
version=parseFloat(temp[1]);
if (version<7) IE6=1;
}

//firefox specific

function prep_map (divid,w,h,cw,ch)
 {
  //whatev -- get ajax map here.
   map_width = w;
   map_height= h;
// both cell width and height were once 48.
   cell_width=cw;
   cell_height=ch;

   if (cell_height<cell_width) cell_width=cell_height;
   if (cell_width<cell_height) cell_height=cell_width;
   MAP_WIDTH=map_width * (cell_width+2*UA) + 4;
   MAP_HEIGHT=map_height * (cell_height+2) + 4;
   war_matrix = new Array(map_width*map_height);
   for (x=0;x<war_matrix.length;x++) { war_matrix[x]=-1; }
 }

function draw_map (divid)
  {
    document.getElementById(divid).style.width = map_width * (cell_width+2*UA) + 4+ "px";
    document.getElementById(divid).style.height = map_height * (cell_height+2*UA) + 4+ "px";
    var maptop=document.getElementById(divid).style.top;
    var mapleft=document.getElementById(divid).style.left;

    var html_div = "";
    var colnum = 1;
    var rownum = 1;
    for (x=0;x<map_width*map_height;x++)
    {
        if (colnum > map_width) { colnum = 1; rownum++; }
        celltop = ((rownum-1)*(cell_height+2*UA)+2*UA);
        cellleft = ((colnum-1)*(cell_width+2*UA)+2*UA);
	html_div += '<div onClick="wowza(\''+divid+x+'\')" id="'+divid+x+'" style="float: left; cursor: pointer; width:'+cell_width+'px; left:'+cellleft+'px; top:'+celltop+'px; height:'+cell_height+'px; text-decoration:none; font-family:verdana;font-size:'+eval(parseInt(Math.min(cell_width,cell_height) / 2))+'px;  z-index:2; -moz-user-select:none; ">&nbsp</div>';
       colnum++;
     }
     document.getElementById(divid).innerHTML = html_div;
}
function wowza(x) {
  var b =x+"";
  var sq = b.substring(11,4);
  if (b.substring(0,4)=='atta') {
   for (z=0;z<25;z++) {
	if (rainbowG[sq]==1) {
        }
   }
  } 
}
function random_colors(divid,rainbow,dices) {
diceG = dices;
rainbowG = rainbow;
for (x=0;x<map_width*map_height;x++) {
	document.getElementById(divid+x).style.border = 'solid';
	document.getElementById(divid+x).style.borderWidth = '1px';
        if (rainbow[x]==7) {
	blacken(divid+x);
	} else {
	document.getElementById(divid+x).style.backgroundColor = colors[rainbow[x]];
	}
	if (dices[x]!=0) {
        if (IE6==1) {
	document.getElementById(divid+x).innerHTML = dices[x]; } else {
	document.getElementById(divid+x).style.backgroundImage = 'url(images/'+dices[x]+'.png)';
	document.getElementById(divid+x).style.backgroundPosition = 'center';
}
	}

}

}

function depress_square(x,y) {
	   //dwr.util.byId('status').innerHTML += '<b>'+name+'</b>: '+x+'<br/>';
	   document.getElementById(x).style.backgroundColor=colorshi[y];
	   document.getElementById(x).style.borderColor = colors[y];
	   document.getElementById(x).style.borderWidth = 1;
	   document.getElementById(x).style.borderStyle = 'inset';

}
function undepress_square(divid,x,y) {
	   //dwr.util.byId('status').innerHTML += '<b>'+name+'</b>: '+x+'<br/>';
	   document.getElementById(divid+x).style.backgroundColor=colors[y];
           document.getElementById(divid+x).style.borderWidth = 1;
           document.getElementById(divid+x).style.borderColor = 'white';
           document.getElementById(divid+x).style.borderStyle = 'solid';

}

function flash_colors(tc) {

    //Effect.Pulsate('user'+tc, {duration: 1});
    //Effect.Pulsate('20');
    for (x=0;x<map_width*map_height;x++) {
	if (rainbowG[x]==tc)
	new Effect.Highlight(''+x, {duration: 1} );	
    }
}
function blacken(x) {
document.getElementById(x).style.backgroundColor=colorshi[7];
	   document.getElementById(x).style.borderColor = colors[7];
	   document.getElementById(x).style.borderWidth = 1;
	   document.getElementById(x).style.backgroundImage = 'none';
	
}
